﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MobileManagement.Library;
using System.Diagnostics;
using HTMailSenderNamespace;
using System.Threading;

namespace HTSwitchServerNamespace
{
    class MobileManagementDoing
    {

        private static void OnMobileNotActiveEvent (Mobile m, EventArgs e)
        {
            Debug.WriteLine("EVENT DETECTED! -> "+m.ToString());  //DEBUG
            
            SimpleAsynchronousExample saMail = new SimpleAsynchronousExample();
            ThreadPool.QueueUserWorkItem(new WaitCallback(saMail.enviarAlarmaServicioSinMoviles), m.ToString());
        }

        public static void MobileManagement_DoWork_Start()
        {
            MobileManagement.Library.MobileManagement myInstance = MobileManagement.Library.MobileManagement.Instance();
            myInstance.MobileNotActive += OnMobileNotActiveEvent;
            myInstance.StartWork();

            //Thread.Sleep(15000);

            //myInstance.StopWork();


        }
        public static void MobileManagement_DoWork_Stop()
        {
            MobileManagement.Library.MobileManagement myInstance = MobileManagement.Library.MobileManagement.Instance();            

            myInstance.StopWork();
        }

        public static void MergeMobile(string movil)
        {
            MobileManagement.Library.MobileManagement myInstance = MobileManagement.Library.MobileManagement.Instance();
            if (!myInstance.ExistMobile(movil)) 
                myInstance.InsertMobile(movil);            
            else
                myInstance.UpdateMobile(movil, DateTime.Now);
            //myInstance.UpdateMobile("22165", DateTime.Now.AddHours(-4));
        }

        
        public static void DeleteMobile(string movil)
        {
            MobileManagement.Library.MobileManagement myInstance = MobileManagement.Library.MobileManagement.Instance();
            myInstance.DeleteMobile(movil);
            //myInstance.DeleteMobile("22165");
        }
        public static void DropTable()
        {
            MobileManagement.Library.MobileManagement myInstance = MobileManagement.Library.MobileManagement.Instance();
            myInstance.DropTable();
            //myInstance.DeleteMobile("22165");
        }
        
    }
}
